package com.hzk.serviceImpl;/*
package com.hzk.serviceImpl;
import com.hzk.mapper.ApplicationMapper;
import com.hzk.mapper.OverdueMapper;
import com.hzk.mapper.RuleMapper;
import com.hzk.pojo.Application;
import com.hzk.pojo.Overdue;
import com.hzk.pojo.Rule;
import com.hzk.pojo.UserBasic;
import com.hzk.vo.RespBean;
import com.hzk.vo.RespBeanEnum;
import com.hzk.vo.RuleVo;
import org.kie.api.KieBase;
import org.kie.api.runtime.KieSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

@Service
public class DroolServiceImpl {
    @Autowired
    private KieBase kieBase;
    @Autowired
    private ApplicationMapper applicationMapper;


    @Autowired
    private OverdueMapper overdueMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private RuleMapper ruleMapper;

    public RespBean executeRule(String token) {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        KieSession kieSession = kieBase.newKieSession();
        //以token为k，拿用户的数据user
        UserBasic user = (UserBasic) redisTemplate.opsForValue().get(token);
        if (user == null) {
            return RespBean.error(RespBeanEnum.NULL_USER_ERROR);
        }
        if (redisTemplate.hasKey("application:" + user.getId())) {
            if (((Boolean) valueOperations.get("application:" + user.getId()))) {
                return RespBean.success(RespBeanEnum.Reappllication_SECERROR);
            }else {
                return RespBean.error(RespBeanEnum.Reappllication_ERROR);
            }
        }
        else {
            //创建Fact对象，并且赋值
            Long id = user.getId();
            */
/*int count = 0;*//*

            Rule rule = ruleMapper.selectById(1);
            Integer agelimit = rule.getAgelimit();
            Long moneylimit = rule.getMoneylimit();
            int payofflimit = rule.getPayofflimit();
            Long yearslimit = rule.getYearslimit();
            int count = 0;
            List<Overdue> overlist = overdueMapper.SeletListById(id);

            int size = overlist.size();
            Application application = new Application();
            if (size != 0) {
                Iterator<Overdue> iterator = overlist.iterator();
                while (iterator.hasNext()) {
                    //迭代器获取每一个用户的逾期记录
                    Overdue next = iterator.next();


                    //年份
                    if (next.getBlacklist() || next.getWorkingState()) {
                        continue;
                    }
                    */
/*if ((new Date().getTime() - next.getLateTime().getTime() < (yearslimit * 3600000 * 24 * 365))) {
                        continue;
                    }
                    if (((next.getPayOffDate().getTime() - next.getLateTime().getTime()) < (payofflimit * 86400000L)
                            && (next.getOverdueRecord() < moneylimit))) {
                        continue;
                    }*//*

                    RuleVo ruleVo = new RuleVo();
                    ruleVo.setAge(agelimit);
                    ruleVo.setMoney(moneylimit);
                    ruleVo.setPayofftime(payofflimit);
                    ruleVo.setTime(yearslimit);
                    ruleVo.setAge1(next.getAge());
                    ruleVo.setMoney1(next.getOverdueRecord());
                    ruleVo.setPayofftime1(next.getPayOffDate().getTime() - next.getLateTime().getTime());
                    ruleVo.setTime1(new Date().getTime() - next.getLateTime().getTime());
                    //将数据交给规则引擎，规则引擎会根据提供的数据进行规则匹配
                    kieSession.insert(ruleVo);
                    //执行规则引擎，触发规则
                    kieSession.fireAllRules();
                    //关闭kieSession
                    kieSession.dispose();

                    application.setId(next.getId());
                    application.setSuccess(true);
                    application.setTime(new Date());
                    application.setUsername(next.getUsername());
                    applicationMapper.insert(application);
                    valueOperations.set("application:" + next.getId(), true);


                }

                */
/*application.setId(user.getId());
                application.setSuccess(true);
                application.setTime(new Date());
                application.setUsername(user.getUsername());
                applicationMapper.insert(application);
                valueOperations.set("application:" + user.getId(), application);*//*

                inserts(application,user,valueOperations,true);

            }
            inserts(application,user,valueOperations,false);
            return RespBean.error(RespBeanEnum.appllication_ERROR);
        }
    }
    public void inserts(Application application,UserBasic user,ValueOperations valueOperations,boolean i){
        application.setId(user.getId());
        application.setSuccess(i);
        application.setTime(new Date());
        application.setUsername(user.getUsername());
        applicationMapper.insert(application);
        valueOperations.set("application:" + user.getId(), i);
    }
}
*/
